

#ifndef THREAD_SEARCH_VIEW_H
#define THREAD_SEARCH_VIEW_H

#include <wx/string.h>
#include <wx/thread.h>
#include <wx/timer.h>
#include <wx/dynarray.h>
#include <wx/datetime.h>
#include <wx/panel.h>
#include <wx/arrstr.h>

#include "editormanager.h"
#include "cbproject.h"
#include "projectmanager.h"

#include "ThreadSearchLoggerBase.h"

class wxToolBar;
class wxStaticBox;
class wxComboBox;
class wxButton;
class wxStaticText;
class cbStyledTextCtrl;
class wxPanel;
class wxMouseEvent;
class wxCommandEvent;
class wxSplitterEvent;
class wxScintillaEvent;
class wxContextMenuEvent;
class wxSplitterWindow;
class wxStaticBoxSizer;
class wxBoxSizer;

class ThreadSearch;
class sThreadSearchEvent;
class ThreadSearchThread;
class ThreadSearchFindData;
class SearchInPanel;
class DirectoryParamsPanel;


class ThreadSearchView: public wxPanel {

    friend class ThreadSearch;
public:



    ThreadSearchView( ThreadSearch& threadSearchPlugin);


    ~ThreadSearchView();

	virtual void Clear();


	void ThreadedSearch(const ThreadSearchFindData& aFindData);


	bool IsSearchRunning();


	void OnThreadExit();


	void Update();


	bool UpdatePreview(const wxString& file, long line);


	void SetSashPosition(int position, const bool redraw = true);
	int  GetSashPosition() const;


	void          SetSearchHistory(const wxArrayString& searchPatterns);
	wxArrayString GetSearchHistory() const;


	void SetLoggerType(ThreadSearchLoggerBase::eLoggerTypes lgrType);


	void PostThreadSearchEvent(const sThreadSearchEvent& event);


	void SetToolBar(wxToolBar* pToolBar) {m_pToolBar = pToolBar;}


	void ShowSearchControls(bool show);


	void ApplySplitterSettings(bool showCodePreview, long splitterMode);
    ThreadSearch* GetThreadSearchPlugin(){return &m_ThreadSearchPlugin;}
private:

    void set_properties();
    void do_layout();


    bool ClearThreadSearchEventsArray();


    bool StopThread();


	void SetMarkerStyle(int marker, int markerType, wxColor fore, wxColor back);
	void UnderlineFoldedLines(bool underline);
	void SetFoldingIndicator(int id);


	ThreadSearchThread* m_pFindThread;
	ThreadSearch&       m_ThreadSearchPlugin;
	wxString            m_PreviewFilePath;
	wxDateTime          m_PreviewFileDate;
	wxMutex             m_MutexSearchEventsArray;
	wxArrayPtrVoid      m_ThreadSearchEventsArray;
	wxTimer             m_Timer;
	long                m_StoppingThread;
	bool                m_bNotebookSizerSet;
	wxWindow*           m_pParent;
	wxFrame*            m_pTSFrame;
protected:


    wxStaticBox* m_pSizerSearchDirItems_staticbox;
    wxComboBox* m_pCboSearchExpr;
    wxButton* m_pBtnSearch;
    wxButton* m_pBtnOptions;


    wxButton* m_pBtnShowDirItems;
    DirectoryParamsPanel* m_pPnlDirParams;
    cbStyledTextCtrl* m_pSearchPreview;
    wxPanel* m_pPnlPreview;
    ThreadSearchLoggerBase* m_pLogger;
    wxPanel* m_pPnlListLog;
    wxSplitterWindow* m_pSplitter;

    wxStaticBoxSizer* m_pSizerSearchDirItems;
    wxBoxSizer*       m_pSizerSearchItems;
    wxToolBar*        m_pToolBar;

	DECLARE_EVENT_TABLE()


	void AddExpressionToSearchCombos(const wxString& expression);



	enum eSearchButtonLabel {
		search,
		cancel,
		skip
	};


	void UpdateSearchButtons(bool enable, eSearchButtonLabel label = skip);


	void EnableControls(bool enable);

public:
    void OnThreadSearchErrorEvent(const sThreadSearchEvent& event);
    void OnCboSearchExprEnter(wxCommandEvent &event);
    void OnBtnSearchClick(wxCommandEvent &event);
    void OnBtnOptionsClick(wxCommandEvent &event);
    void OnBtnShowDirItemsClick(wxCommandEvent &event);
    void OnSplitterDoubleClick(wxSplitterEvent &event);
	void OnMarginClick(wxScintillaEvent& event);
	void OnContextMenu(wxContextMenuEvent& event);
    void OnLoggerClick      (const wxString& file, long line);

    void OnLoggerDoubleClick(const wxString& file, long line);


	void OnChkSearchOpenFiles(wxCommandEvent &event);
	void OnChkSearchSnippetFiles(wxCommandEvent &event);
	void OnChkSearchWorkspaceFiles(wxCommandEvent &event);
	void OnChkSearchDirectoryFiles(wxCommandEvent &event);
	void OnChkSearchDirRecurse(wxCommandEvent &event);
	void OnChkSearchDirHidden(wxCommandEvent &event);

	void OnTxtSearchMaskTextEvent(wxCommandEvent &event);
	void OnTxtSearchDirPathTextEvent(wxCommandEvent &event);

	void OnTmrListCtrlUpdate(wxTimerEvent& event);

};

#endif
